package com.jrtc.backend.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.base.Strings;
import com.jrtc.base.config.dto.ResultDTO;
import com.jrtc.base.config.dto.ResultDTOBuilder;
import com.jrtc.base.entity.bo.PrescriptionLabelOne;
import com.jrtc.service.PrescriptionLabelOneService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 运动处方标签一级分类(PrescriptionLabelOne)表控制层
 *
 * @author makejava
 * @since 2022-09-08 13:35:34
 */
@RestController
@RequestMapping("prescriptionLabelOne")
public class PrescriptionLabelOneController {
    /**
     * 服务对象
     */
    @Resource
    private PrescriptionLabelOneService prescriptionLabelOneService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public PrescriptionLabelOne selectOne(Integer id) {
        return this.prescriptionLabelOneService.queryById(id);
    }
    
    @RequestMapping("getPrescriptionLabelOneList")
    public ResultDTO getPrescriptionLabelOneList(@RequestBody PrescriptionLabelOne prescriptionLabelOne)
    {
        IPage<PrescriptionLabelOne> ipage = prescriptionLabelOneService.queryPrescriptionLabelOneList(prescriptionLabelOne);
        return ResultDTOBuilder.success(ipage);
    }

    /**
     * 运动处方标签列表
     * */
    @RequestMapping("getAllLabel")
    public ResultDTO getAllLabel()
    {
        List<PrescriptionLabelOne> lstData = prescriptionLabelOneService.queryAllLabel(0);
        if (lstData.size() > 0)
        {
           return ResultDTOBuilder.success(lstData);
        }
        return ResultDTOBuilder.success("");
    }

    @RequestMapping("insertPrescriptionLabelOne")
    public ResultDTO insertPrescriptionLabelOne(@RequestBody PrescriptionLabelOne prescriptionLabelOne)
    {
        PrescriptionLabelOne tmpPrescriptionLabelOne = prescriptionLabelOneService.insert(prescriptionLabelOne);
        if (tmpPrescriptionLabelOne != null)
        {
           return ResultDTOBuilder.success("添加成功！");
        }
        return ResultDTOBuilder.failureMsg("添加失败！");
    }

    @RequestMapping("getPrescriptionLabelOneById")
    public ResultDTO getPrescriptionLabelOneById(@RequestBody Map<String, String> map)
    {
        String prescriptionLabelOneId = map.get("prescriptionLabelOneId");
        PrescriptionLabelOne prescriptionLabelOne = prescriptionLabelOneService.queryById(Integer.valueOf(prescriptionLabelOneId));
        if (Strings.isNullOrEmpty(prescriptionLabelOneId) || prescriptionLabelOne==null)
        {
            return ResultDTOBuilder.failureMsg("信息有误！");
        }
        return ResultDTOBuilder.success(prescriptionLabelOne);
    }

    @RequestMapping("updatePrescriptionLabelOne")
    public ResultDTO updatePrescriptionLabelOne(@RequestBody PrescriptionLabelOne prescriptionLabelOne)
    {
        if (prescriptionLabelOne==null)
        {
            return ResultDTOBuilder.failureMsg("信息有误！");
        }
        if (prescriptionLabelOneService.update(prescriptionLabelOne)!=null)
        {
            return ResultDTOBuilder.success("修改信息成功！");
        }
        return ResultDTOBuilder.failureMsg("修改信息失败！");
    }
    
    @RequestMapping("deletePrescriptionLabelOne")
    public ResultDTO deletePrescriptionLabelOne(@RequestBody Map<String,String> map)
    {
        String prescriptionLabelOneId = map.get("prescriptionLabelOneId");
        if (!Strings.isNullOrEmpty(prescriptionLabelOneId))
        {
            if (prescriptionLabelOneService.deleteById(Integer.valueOf(prescriptionLabelOneId)))
            {
                return ResultDTOBuilder.success("删除成功！");
            }
            return ResultDTOBuilder.failureMsg("删除失败！");
        }
        return ResultDTOBuilder.failureMsg("编号不正确！");
    }
}